home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / libraries / db_info.inc.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  7.9 KB  |  248 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * Gets the list of the table in the current db and informations about these
  5.  * tables if possible
  6.  *
  7.  * fills tooltip arrays and provides $tables, $num_tables, $is_show_stats
  8.  * and $db_is_information_schema
  9.  *
  10.  * staybyte: speedup view on locked tables - 11 June 2001
  11.  *
  12.  * @uses    PMA_MYSQL_INT_VERSION
  13.  * @uses    $cfg['ShowStats']
  14.  * @uses    $cfg['ShowTooltip']
  15.  * @uses    $cfg['ShowTooltipAliasTB']
  16.  * @uses    $cfg['SkipLockedTables']
  17.  * @uses    $GLOBALS['db']
  18.  * @uses    PMA_fillTooltip()
  19.  * @uses    PMA_checkParameters()
  20.  * @uses    PMA_escape_mysql_wildcards()
  21.  * @uses    PMA_DBI_query()
  22.  * @uses    PMA_backquote()
  23.  * @uses    PMA_DBI_num_rows()
  24.  * @uses    PMA_DBI_fetch_row()
  25.  * @uses    PMA_DBI_fetch_assoc()
  26.  * @uses    PMA_DBI_free_result()
  27.  * @uses    PMA_DBI_get_tables_full()
  28.  * @uses    PMA_isValid()
  29.  * @uses    preg_match()
  30.  * @uses    preg_quote()
  31.  * @uses    uksort()
  32.  * @uses    strnatcasecmp()
  33.  * @uses    count()
  34.  * @uses    addslashes()
  35.  * @version $Id: db_info.inc.php 10542 2007-08-01 19:16:05Z lem9 $
  36.  */
  37.  
  38. /**
  39.  * requirements
  40.  */
  41. require_once './libraries/common.inc.php';
  42.  
  43. /**
  44.  * limits for table list
  45.  */
  46. if (! isset($_SESSION['table_limit_offset'])) {
  47.     $_SESSION['table_limit_offset'] = 0;
  48. }
  49. if (isset($_REQUEST['pos'])) {
  50.     $_SESSION['table_limit_offset'] = (int) $_REQUEST['pos'];
  51. }
  52. $pos = $_SESSION['table_limit_offset'];
  53.  
  54. /**
  55.  * fills given tooltip arrays
  56.  *
  57.  * @uses    $cfg['ShowTooltipAliasTB']
  58.  * @uses    $GLOBALS['strStatCreateTime']
  59.  * @uses    PMA_localisedDate()
  60.  * @uses    strtotime()
  61.  * @param   array   $tooltip_truename   tooltip data
  62.  * @param   array   $tooltip_aliasname  tooltip data
  63.  * @param   array   $table              tabledata
  64.  */
  65. function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
  66. {
  67.     if (empty($table['Comment'])) {
  68.         $table['Comment'] = $table['Name'];
  69.     } else {
  70.         // why?
  71.         $table['Comment'] .= ' ';
  72.     }
  73.  
  74.     if ($GLOBALS['cfg']['ShowTooltipAliasTB']
  75.      && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
  76.         $tooltip_truename[$table['Name']] = $table['Comment'];
  77.         $tooltip_aliasname[$table['Name']] = $table['Name'];
  78.     } else {
  79.         $tooltip_truename[$table['Name']] = $table['Name'];
  80.         $tooltip_aliasname[$table['Name']] = $table['Comment'];
  81.     }
  82.  
  83.     if (isset($table['Create_time']) && !empty($table['Create_time'])) {
  84.         $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCreateTime']
  85.              . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
  86.     }
  87.  
  88.     if (! empty($table['Update_time'])) {
  89.         $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
  90.              . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
  91.     }
  92.  
  93.     if (! empty($table['Check_time'])) {
  94.         $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
  95.              . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
  96.     }
  97. }
  98.  
  99. PMA_checkParameters(array('db'));
  100.  
  101. /**
  102.  * @global bool whether to display extended stats
  103.  */
  104. $is_show_stats = $cfg['ShowStats'];
  105.  
  106. /**
  107.  * @global bool whether selected db is information_schema
  108.  */
  109. $db_is_information_schema = false;
  110.  
  111. if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
  112.     $is_show_stats = false;
  113.     $db_is_information_schema = true;
  114. }
  115.  
  116. /**
  117.  * @global array information about tables in db
  118.  */
  119. $tables = array();
  120.  
  121. // When used in Nested table group mode, only show tables matching the given groupname
  122. if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
  123.     $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
  124. } else {
  125.     $tbl_group_sql = '';
  126. }
  127.  
  128. if ($cfg['ShowTooltip']) {
  129.     $tooltip_truename = array();
  130.     $tooltip_aliasname = array();
  131. }
  132.  
  133. // Special speedup for newer MySQL Versions (in 4.0 format changed)
  134. if (true === $cfg['SkipLockedTables']) {
  135.     $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
  136.  
  137.     // Blending out tables in use
  138.     if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
  139.         while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
  140.             // if in use memorize tablename
  141.             if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
  142.                 $sot_cache[$tmp[0]] = true;
  143.             }
  144.         }
  145.         PMA_DBI_free_result($db_info_result);
  146.  
  147.         if (isset($sot_cache)) {
  148.             $db_info_result = PMA_DBI_query(
  149.                 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
  150.                 null, PMA_DBI_QUERY_STORE);
  151.             if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
  152.                 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
  153.                     if (!isset($sot_cache[$tmp[0]])) {
  154.                         $sts_result  = PMA_DBI_query(
  155.                             'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
  156.                              . ' LIKE \'' . addslashes($tmp[0]) . '\';');
  157.                         $sts_tmp     = PMA_DBI_fetch_assoc($sts_result);
  158.                         PMA_DBI_free_result($sts_result);
  159.                         unset($sts_result);
  160.  
  161.                         if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
  162.                             $sts_tmp['Type'] =& $sts_tmp['Engine'];
  163.                         }
  164.  
  165.                         if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
  166.                          && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
  167.                             continue;
  168.                         }
  169.  
  170.                         if ($cfg['ShowTooltip']) {
  171.                             PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
  172.                         }
  173.  
  174.                         $tables[$sts_tmp['Name']]    = $sts_tmp;
  175.                     } else { // table in use
  176.                         $tables[$tmp[0]]    = array('Name' => $tmp[0]);
  177.                     }
  178.                 }
  179.                 if ($GLOBALS['cfg']['NaturalOrder']) {
  180.                     uksort($tables, 'strnatcasecmp');
  181.                 }
  182.  
  183.                 $sot_ready = true;
  184.             } elseif ($db_info_result) {
  185.                 PMA_DBI_free_result($db_info_result);
  186.             }
  187.             unset($sot_cache);
  188.         }
  189.         unset($tmp);
  190.     } elseif ($db_info_result) {
  191.         PMA_DBI_free_result($db_info_result);
  192.     }
  193. }
  194.  
  195. if (! isset($sot_ready)) {
  196.     if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
  197.         // only tables for selected group
  198.         $tables = PMA_DBI_get_tables_full($db, $tbl_group, true);
  199.     } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
  200.         // only tables for selected group,
  201.         // but grouping is done on comment ...
  202.         $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment');
  203.     } else {
  204.         // all tables in db
  205.         // - get the total number of tables
  206.         $tables = PMA_DBI_get_tables($db);
  207.         $total_num_tables = count($tables);
  208.         if (isset($sub_part) && $sub_part == '_export') {
  209.             // (don't fetch only a subset if we are coming from db_export.php,
  210.             // because I think it's too risky to display only a subset of the 
  211.             // table names when exporting a db)
  212.             /**
  213.              *
  214.              * @todo Page selector for table names?
  215.              */
  216.             $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false);
  217.         } else {
  218.             // fetch the details for a possible limited subset
  219.             $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true);
  220.         }
  221.     }
  222.  
  223.     if ($cfg['ShowTooltip']) {
  224.         foreach ($tables as $each_table) {
  225.             PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
  226.         }
  227.     }
  228. }
  229.  
  230. /**
  231.  * @global int count of tables in db
  232.  */
  233. $num_tables = count($tables);
  234. if (! isset($total_num_tables)) {
  235.     $total_num_tables = $num_tables;
  236. }
  237.  
  238. /**
  239.  * cleanup
  240.  */
  241. unset($each_table, $tbl_group_sql, $db_info_result);
  242.  
  243. /**
  244.  * Displays top menu links
  245.  */
  246. require './libraries/db_links.inc.php';
  247. ?>
  248.